###
### controller
###


{{- define "csi_controller_args" }}
- "--address=$(MY_POD_IP):12302"
- "--endpoint=unix:///csi/csi.sock"
- {{ printf "--folder-id=%s" (.Values.cloudProviderYandex.internal.providerClusterConfiguration.provider.folderID | required "providerClusterConfiguration.provider.folderID is required") | quote }}
- {{ printf "--cluster-uuid=%s" .Values.global.discovery.clusterUUID | quote }}
{{- end }}

{{- define "csi_controller_envs" }}
- name: MY_POD_IP
  valueFrom:
    fieldRef:
      fieldPath: status.podIP
- name: YANDEX_AUTH_KEYS
  valueFrom:
    secretKeyRef:
      name: csi-credentials
      key: serviceAccountJSON
{{- include "helm_lib_envs_for_proxy" . }}
{{- end }}

{{- $csiControllerImage := include "helm_lib_module_image" (list . "yandexCsiPlugin") }}

{{- $csiControllerConfig := dict }}
{{- $_ := set $csiControllerConfig "controllerImage" $csiControllerImage }}
{{- $_ := set $csiControllerConfig "snapshotterEnabled" false }}
{{- $_ := set $csiControllerConfig "additionalControllerArgs" (include "csi_controller_args" . | fromYamlArray) }}
{{- $_ := set $csiControllerConfig "additionalControllerEnvs" (include "csi_controller_envs" . | fromYamlArray) }}

{{- include "helm_lib_csi_controller_manifests" (list . $csiControllerConfig) }}

###
### node
###

{{- define "csi_node_args" }}
- "--endpoint=unix:///csi/csi.sock"
{{- end }}

{{- define "csi_node_envs" }}
- name: YANDEX_AUTH_KEYS
  valueFrom:
    secretKeyRef:
      name: csi-credentials
      key: serviceAccountJSON
{{- end }}

{{- $csiNodeConfig := dict }}
{{- $_ := set $csiNodeConfig "nodeImage" $csiControllerImage }}
{{- $_ := set $csiNodeConfig "driverFQDN" "yandex.csi.flant.com" }}
{{- $_ := set $csiNodeConfig "additionalNodeArgs" (include "csi_node_args" . | fromYamlArray) }}
{{- $_ := set $csiNodeConfig "additionalNodeEnvs" (include "csi_node_envs" . | fromYamlArray) }}

{{- include "helm_lib_csi_node_manifests" (list . $csiNodeConfig) }}
